﻿// <copyright file="Page.xaml.cs" company="Microsoft Corporation">
// Copyright (c) 2008 All Right Reserved
// </copyright>
// <author>Michael S. Scherotter</author>
// <email>mischero@microsoft.com</email>
// <date>2008-10-10</date>
// <summary>Page user control</summary>

namespace PreviewSilverlight
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Browser;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Markup;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;

    /// <summary>
    /// Preview silveright page
    /// </summary>
    public partial class Page : UserControl
    {
        #region Constructors
        /// <summary>
        /// Initializes a new instance of the Page class.
        /// </summary>
        public Page()
        {
            InitializeComponent();
        }
        #endregion

        /// <summary>
        /// User control loaded event
        /// </summary>
        /// <param name="sender">user control</param>
        /// <param name="e">routed event arguments</param>
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                var xamlTextElement = HtmlPage.Document.GetElementById("XamlText");

                var xaml = xamlTextElement.GetProperty("value") as string;

                var content = XamlReader.Load(xaml);
                
                ////var content = new UserControl();

                ////System.Windows.Application.LoadComponent(content, new Uri("preview.xaml", UriKind.Relative));

                this.TextParent.Content = content;
            }
            catch (System.Exception se)
            {
                System.Diagnostics.Debug.WriteLine(se.Message);
            }
        }
    }
}
